package edu.nepu.flink.api.combinStream;

import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Date 2024/2/28 22:37
 * @Created by chenshuaijun
 */
public class UnionOperator {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Integer> streamSource1 = env.fromElements(1, 2, 3, 4);
        DataStreamSource<Integer> streamSource2 = env.fromElements(4,5,6,7);
        DataStreamSource<Integer> streamSource3 = env.fromElements(8,9,10,11);
        /**
         * 使用union进行合流操作的时候，需要注意以下几点
         * （1） union一次可以合并多条流
         * （2）多条流的类型必须是相同的
         */

        DataStream<Integer> unionStream = streamSource1.union(streamSource2, streamSource3);

        unionStream.print();

        env.execute();

    }
}
